package com.richard.room.operator.api.builder;

import androidx.room.RoomDatabase;

import com.richard.room.operator.api.Entity;
import com.richard.room.operator.api.helper.SQLiteHelper;
import com.richard.room.operator.api.statement.DeleteSQL;

/**
 * @author: Richard
 * @createDate: 2023/8/16 17:12
 * @version: 1.0
 * @description: delete builder
 */
public class DeleteBuilder<T> extends BasicConditionRelationBuilder<T, DeleteBuilder<T>> {

    private final RoomDatabase db;
    private final DeleteSQL<T> sql;

    public DeleteBuilder(RoomDatabase db, Entity<T> entity) {
        this.db = db;
        this.sql = new DeleteSQL<>(entity);
        this.sql.where = super.condition;
    }

    public void delete() {
        SQLiteHelper.execDeleteSql(db, sql, false);
    }

    /**
     * 删除并返回影响行数
     *
     * @return 影响行数
     */
    public long deleteAndReturnRowCount() {
        return SQLiteHelper.execDeleteSql(db, sql, true);
    }
}
